package com.goktech.project.hmw.controller;

import com.goktech.project.hmw.mapper.City;
import com.goktech.project.hmw.service.ICityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/city")
public class CityController {

	@Autowired
	ICityService cityService;

	@Autowired
	private StringRedisTemplate redisTemplate;
	/**
	 * create by yej@goktech.cn
	 * description 通过乡镇名称获取数据
	 * @param reqMap 乡镇名称
	 * @return JSON
	 */
	@PostMapping("/get")
	public City getCity(@RequestBody Map<String,String> reqMap) {
		return cityService.getCity(reqMap.get("name"));
	}

	/**
	 * create by yej@goktech.cn
	 * 通过区县获取数据集合
	 * @param reqMap 区县名称
	 * @return 数据集合JSON
	 */
//	@PostMapping ("/list")
//	public List<City> listCity(@RequestBody Map<String,String> reqMap){
//		return cityService.listCity(reqMap.get("county"));
//	}

	/**
	 * create by yej@goktech.cn
	 * description 获取所有区县数据
	 * @return
	 */
	@PostMapping("/listall")
	public List<City> listAllCity(){
		return cityService.listAllCity();
	}

	/**
	 * create by yej@goktech.cn
	 * description 获取所有乡镇数据包含人数
	 * @return
	 */
	@PostMapping("/listtotal")
	public List<City> listAllContainTotal(){
//		List<City> list=null;
//		String county="listtotalss";
//		if (redisTemplate.hasKey(county)){
//			ValueOperations<String,String> operations=redisTemplate.opsForValue();
//			String json=operations.get(county,0,-1);
//			JSONArray jsonArray = JSONArray.fromObject(json);
//			list = (List<City>) JSONArray.toCollection(jsonArray,City.class);
//		}else{
//			list= cityService.listAllCityContainTotal();
//			ValueOperations<String,String> operations=redisTemplate.opsForValue();
//			String json=JSONArray.fromObject(list).toString();
//			operations.set(county,json);
//		}
		return cityService.listAllCityContainTotal();

	}

	/**
	 *
	 * 获取全市发放总金额
	 * @return
	 */
	@PostMapping("/totalmoney")
	public String total_money(){
		return cityService.total_money();
	}
}
